import uiRouter from 'angular-ui-router'
// import angularUiBootstrap from 'angular-ui-bootstrap'
import oclazyload from 'oclazyload'
import routing from './app/routing.js'
import directive from './app/directive.js'
import server from './app/server.js'
import filters from './filter'
// require('../sass/comm.scss');
import '~assets/css/bootstrap.min.css'
import '~assets/css/bootstrap-theme.min.css'
// import '~assets/css/viewer.css'
import '~assets/css/viewer.min.css'
import "~assets/css/app.less";
import '~assets/css/login.less'
import '~assets/css/layer.less'
import '~assets/css/global.less'
import '~assets/css/skin.less'
import '~plugins/lib/treeview/jquery.treeview.css'
import $_fn from '~plugins'  //JS全局插件

window.$_fn = $_fn
import '~plugins/lib/css/jquery-rebox.css'
// import '~plugins/lib/js/jquery.zoom.js'
import '~plugins/lib/js/autocomplete-rebox-multilevel-deta.js'
import '~plugins/lib/js/data_cn.js'
import '~plugins/lib/treeview/jquery.cookie.js'
import '~plugins/lib/treeview/jquery.treeview.js'
const app = angular.module('app', [uiRouter,oclazyload,routing,directive,server,'ui.bootstrap'])
//过滤器
Object.keys(filters).forEach(function(k){
    app.filter(k, filters[k])
})
app.config(function($stateProvider,$urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise("login");
    $locationProvider.html5Mode(true);
})
.run(function(http,$rootScope,$location,$state) {
    var userInfo = $_fn.getLocal('userHelp')
    //判断是否登录
    http.post('isLogin.do',{},function(data){
        if(data.errcode < 0){
            $location.path('/login')
        }else{
            if($location.path() =='/login'){
                $location.path('/index')
            } 
        }
    })
    //即实更新权限
    if($location.path() !== '/login'){
        http._post('getAllRights.do',{id:userInfo.id},function(data){
            var path = $location.path()
            if(data.errcode > 0){
                var _data = data.data
                $_fn.setLocal('menu', _data)
                // var curRoute =_data.find(li => li.state=== path.split('/')[0])
                // $_fn.setLocal('parentMenu',curRoute)
            }
        })
    }
    $rootScope.breadcrumbArr = []
    $rootScope.toast = []
    $rootScope.detailName = ''
})
